"""

"""

"""
编码
str.encode(encoding='utf-8', errors='strict|ignore|replace')
"""
# 编码
s = '你好，世界'
encoded_gbk = s.encode('gbk')
encoded_utf8 = s.encode('utf-8')
print('encoded_gbk:%s' % encoded_gbk, end='\n')
print('encoded_utf8:%s' % encoded_utf8, end='\n')

# 编码中的 error 处理
s = '耶✌'
# encoded = s.encode('gbk')
# print('encoded: %s' % encoded)
# 替换
encoded_replace = s.encode('gbk', errors='replace')
print('encoded_replace:%s' % encoded_replace, end='\n')
# 忽略
encoded_ignore = s.encode('gbk', errors='ignore')
print('encoded_ignore:%s' % encoded_ignore, end='\n')
# 严格
# encoded_strict = s.encode('gbk', errors='strict')
# print('encoded_strict:%s' % encoded_strict, end='\n')

"""
解码
bytes.decode(encoding='utf-8', errors='strict|ignore|replace')
"""
# 严格
decoded_gbk = bytes.decode(encoded_gbk, 'gbk')
print('decoded_gbk: %s' % decoded_gbk)
# 忽略
decoded_ignore = bytes.decode(encoded_ignore, 'gbk', errors='ignore')
print('decoded_ignore:%s' % decoded_ignore)
# 替换
decoded_replace = bytes.decode(encoded_replace, 'gbk', errors='replace')
print('decoded_replace: %s' % decoded_replace)



